package com.beamfield.controller.manage.steelplant;

import com.beamfield.common.ApiResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.BeamLocationMapping;
import com.beamfield.model.BeamLocationMappingDTO;
import com.beamfield.service.serviceimpl.manage.steelplant.BeamLocationMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 */
@Controller
@RequestMapping(value = "/beamLocationMappingController")
public class BeamLocationMappingController extends BaseController {


    @Autowired
    private BeamLocationMappingService beamLocationMappingService;
    
    
    


    @RequestMapping(value = "/addBeamLocationMapping")
    @ResponseBody
    public ApiResult addBeamLocationMapping(BeamLocationMapping BeamLocationMapping, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        BeamLocationMapping.setBeam_id(beamId);

        int result = 0;
        try {
            result = beamLocationMappingService.addBeamLocationMapping(BeamLocationMapping);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }

    }

    @RequestMapping(value = "/delBeamLocationMapping")
    @ResponseBody
    public ApiResult delBeamLocationMapping(BeamLocationMapping BeamLocationMapping, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        BeamLocationMapping.setBeam_id(beamId);
        int result = 0;
        try {
            result = beamLocationMappingService.delBeamLocationMapping(BeamLocationMapping);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/updelBeamLocationMapping")
    @ResponseBody
    public ApiResult updelBeamLocationMapping(BeamLocationMapping BeamLocationMapping, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        BeamLocationMapping.setBeam_id(beamId);
        int result = 0;
        try {
            result = beamLocationMappingService.updelBeamLocationMapping(BeamLocationMapping);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }


    }

    @RequestMapping(value = "/queryBeamLocationMappingAll")
    @ResponseBody
    public  List<BeamLocationMapping>  queryBeamLocationMappingAll(BeamLocationMappingDTO BeamLocationMappingDTO, HttpServletRequest request) {

        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);


        BeamLocationMappingDTO.setBeam_id(beamId);

        List<BeamLocationMapping> BeamLocationMappings = beamLocationMappingService.queryBeamLocationMappingAll(BeamLocationMappingDTO);
        return BeamLocationMappings;

    }

    @RequestMapping(value = "/queryBeamLocationMappingOne")
    @ResponseBody
    public BeamLocationMapping queryBeamLocationMappingOne(BeamLocationMapping BeamLocationMapping, HttpServletRequest request) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        BeamLocationMapping.setBeam_id(beamId);
        return beamLocationMappingService.queryBeamLocationMappingOne(BeamLocationMapping);
    }


   

}
